<?
include('../../src/inst.conf.php');
include('../../src/functions.php');

?>
<!-- JavaScript -->
<script src="./js/jquery.min.js"></script>
<script src="./js/jqueryui.min.js"></script>
<script src="./js/jquery.cookies.js"></script>
<script src="./js/jquery.pjax.js"></script>
<script src="./js/formalize.min.js"></script>
<script src="./js/jquery.metadata.js"></script>
<script src="./js/jquery.validate.js"></script>
<script src="./js/jquery.checkboxes.js"></script>
<script src="./js/jquery.chosen.js"></script>
<script src="./js/jquery.fileinput.js"></script>
<script src="./js/jquery.datatables.js"></script>
<script src="./js/jquery.sourcerer.js"></script>
<script src="./js/jquery.tipsy.js"></script>
<script src="./js/jquery.calendar.js"></script>
<script src="./js/jquery.inputtags.min.js"></script>
<script src="./js/jquery.wymeditor.js"></script>
<script src="./js/jquery.livequery.js"></script>
<script src="./js/jquery.flot.min.js"></script>
<script src="./js/jquery.watch.js"></script>
<script src="./js/application.js"></script>
<?
if(isset($_GET['general'])){
?>
<div class="box">
	<div class="box-header">
		<h1>Inlog pagina</h1>
	</div>
	<div class="box-content">
  		<form action="javascript:;" method="post" id="general" >
  			<div class="column-left">
  				<p>
  					<input type="text" id="title" placeholder="Titel" name="title" class="{validate:{required:true, minlength:3}}" value="<?= $cfg['general']['welcome']['title'];?>"/>
  				</p>
  				<p>
  				  <textarea id="textarea" name="textarea" class="{validate:{required:true}}"><?= $cfg['general']['welcome']['text'];?></textarea>
  				</p>
  			</div>
  			<div class="column-right">
  				<p>
  				 	<input type="checkbox" name="option1" id="LLaanmelden" />
  					<label for="option1">Leerlingen kunnen zich aanmelden</label>
  				</p>
  				<p>
  					<small>Maximale <a href="#" title="Als een gebruiker deze tijd inactief is geweest, moet opnieuw het wachtwoord ingevoerd worden" class="tooltip">IDLE</a> time: <span id="time"><?=$cfg['general']['idle']['min'];?></span> minuten</small>
  					<div class="slider {range: 'min', min: 2, max: 60, value: <?=$cfg['general']['idle']['min'];?>} width:80%" id="idle"></div><input type="hidden" id="timemouttime" name="timeouttime" value="<?=$cfg['general']['idle']['min'];?>"/>
  				</p>
  			</div>
  			<div class="clear"></div>
  			<div class="action_bar">
  				<input type="submit" class="button blue" value="Opslaan" onclick=""/>
  			    <a href="#modal" class="modal button">Annuleren</a>
  			</div>
  			
  		</form>
  	</div>
</div>
  <script type="text/javascript">
  $(document).ready(function() {
  	var min =  <?=$cfg['general']['idle']['min'];?>;
  	var percentage = (min/60)*100;
  	$('#idle').find('div').width(percentage+"%");
  	$('#idle').find('a').css("left", percentage+"%");
  $('#idle').find('div').watch('width', function(){
  	var width = $('#idle').find('div').width();
  	var parentWidth = $('#idle').width();
  	var percent = width/parentWidth;
  	var min = 60*percent;
  	if(min<2){
  		min=2;
  		$('#idle').find('div').width("3%");
  		$('#idle').find('a').css("left", "3%");
  	}
  	min = Math.round(min);
  	$('span#time').html(min);
  	$('#timemouttime').val(min);
  });
});
  $('#general').on('submit', function(){
  	var values=$('#general').serialize();
  	$.ajax({
  		type: "POST",
  		data: values,
  		url: '',
  		dataType: 'JSON',
  		success: function(response) {
  			if(response.success==true)
  			{
  				message(response.message, "Success", "success");
  			}else if(response.error==true)
  			{
  				message(response.message, "Error", "error");
  			}
  		},
  		error: function(jqXHR, textStatus, errorThrown) {
  			if(textStatus=="timeout")
  			{	
  				//$.notify({text:'The page had an timeout', title:'Error', icon:'images/dialog-error.png'});
  			}else 
  			{
  				message(jqXHR.responseText, "Error", "error");
  			}
  		}
  	});
  });
  </script>
  
  

<?
}elseif(isset($_GET['database'])){

//kijk welke databases er op de server te bereiken zijn
$query =mysql_query("show databases");
while($data = mysql_fetch_assoc($query)){
	if($data['Database'] != "default_schema" AND $data['Database'] != "information_schema"){
		if ($cfg['db']['database'] == $data['Database']){
			@$databases .= "<option value='".$data['Database']."' SELECTED>".$data['Database']."</option>";
		}else{
			@$databases .= "<option value='".$data['Database']."'>".$data['Database']."</option>"; 
		}
	}
}

$tbl=array();
// Haal de database statestieken op
$result = mysql_query("SHOW TABLE STATUS");
while($row = mysql_fetch_array($result)) {
    /* We return the size in bytes */
    $tbl[$row['Name']]['ROWS'] = $row['Rows'];
    $tbl[$row['Name']]['SIZE_b'] = ($row[ "Data_length" ] + $row[ "Index_length" ]);
}
$tbl['Totaal']['ROWS'] =0;
$tbl['Totaal']['SIZE_b'] = 0;
?>

<script>
$('#modalcontainer').html('<div id="modal_sql_restore" class="box"><div class="box-header"><h1>Database DUMP[backup] terugzetten</h1></div><div class="box-content"><form name="restore"><div class="column-left"><p><input type="text" id="textfield" name="textfield" placeholder="This is a textfield" class="{validate: {required:true}}"><span class="icon tick valid"></span></p><p><input type="file" id="file" name="file" placeholder="SQL DUMP" /></p></div><div class="column-right"><p><input type="text" id="textfield2" name="textfield2" placeholder="This is another textfield"><small>This could be small explanation of some sort.</small></p></div><div class="clear"></div><div class="action_bar"><input type="submit" class="button red" value="Submit" id="submit2" name="submit2"><a href="#" class="close button">Close window</a></div></form></div></div>');
</script>




<div class="column-left">
	<div class="box">
		<div class="box-header">
	    	<h1>Database instellingen</h1>
	    </div>
	    <div class="box-content">
	    	<form name="db_settings" action="/" method="post">
	    		<div class="column">
	    			<p>
	    				<input type="text" id="cfg_db_host" placeholder="Host" name="cfg[db][host]" class="{validate:{required:true}}" value="<?= $cfg['db']['host'];?>"/>
	    			</p>
	    			<p>
	    				<input type="text" id="cfg_db_user" placeholder="Gebruikersnaam" name="cfg[db][user]" class="{validate:{required:true}}" value="<?= $cfg['db']['user'];?>"/>
	    			</p>
	    			<p>
	    				<input type="password" id="cfg_db_password" placeholder="Wachtwoord" name="cfg[db][pass]" class="{validate:{required:true}}" value="<?= $cfg['db']['password'];?>"/>
	    			</p>
	    			<p>
	    			  <select name="cfg[db][database]" id="cfg_db_database_sel" placeholder="Database" class="{validate:{required:true}}">
	    			    <?=$databases;?>
	    			  </select>
	    			</p>
	    			<p class="warning">
	    			  Waarschuwing: Zorg voordat u de database verbinding wijzigt u alle Data gekopieerd heeft naar de nieuwe server. anders is het niet meer mogenlijk om in te loggen en moet u handmatig './src/opties.php' aanpassen
	    			</p>
	    		</div>
	    		<div class="clear"></div>
	    		<div class="action_bar">
	    			<input type="submit" class="button blue" value="opslaan" onclick=""/>
	    			<input type="reset" class="button " value="Annuleren"/>
	    		</div>
	    	</form>
	    </div>
	</div>
</div>
<div class="column-right">
	<div class="box">
	    <div class="box-header">
	      <span class="icon16 chart"></span><h1>Database statistieken [<?= $cfg['db']['database'];?>]</h1>
	    </div>
	
	    <ul class="statistics">
	      <? 
	       foreach ($tbl as $key => $value) {
	       		if ($key <> "Totaal"){
			       	echo "<li>";
			       	echo "<a href=\"#\">";
			       	echo "<span>".$tbl[$key]['ROWS']."</span>";
			       	echo "waarden opgeslagen in $key [".BytesToGreater($tbl[$key]['SIZE_b'])."]";
			       	echo "</a>";
			       	echo "</li>";
			       	$tbl['Totaal']['ROWS'] = $tbl['Totaal']['ROWS'] + $tbl[$key]['ROWS'];
			       	$tbl['Totaal']['SIZE_b'] = $tbl['Totaal']['SIZE_b'] + $tbl[$key]['SIZE_b'];
		   		}else{
		   			echo "<li>";
		   			echo "<a href=\"#\">";
		   			echo "<span>".$tbl[$key]['ROWS']."</span>";
		   			echo "Totaal opgeslagen waarden [".BytesToGreater($tbl[$key]['SIZE_b'])."]";
		   			echo "</a>";
		   			echo "</li>";
		   		}
	       }
	       
	       ?>
	    </ul>
	  <div class="action_bar">
	    <a href="./pages/mysql_dump.php?file" class="button small"><span class="icon16 export"></span>DUMP van de database [Backup]</a>
	    <a href="#modal_sql_restore" class="modal button small"><span class="icon16 refresh"></span>Zet terug</a>
	  </div>
	</div>
</div>


<?
 
}elseif(isset($_GET['mail'])){

}elseif(isset($_GET['Gedragcirkel'])){

	foreach ($cfg['general']['eigenschappen']['ik'] as $key => $value) {@$eigenschappen['ik'] .=$value . ",";}
	foreach ($cfg['general']['eigenschappen']['werk'] as $key => $value) {@$eigenschappen['werk'] .=$value . ",";}
	foreach ($cfg['general']['eigenschappen']['kinderen'] as $key => $value) {@$eigenschappen['kinderen'] .=$value . ",";}
	foreach ($cfg['general']['eigenschappen']['volwassenen'] as $key => $value) {@$eigenschappen['volwassenen'] .=$value . ",";}

	?>
	<div class="box">
		<div class="box-header">
			<h1>Gedragcirkel Algemeen</h1>
		</div>
		<div class="box-content">
	  		<form action="javascript:;" method="post" id="general" >
	  			<div class="column-left">
	  				<table>
	  				<tr><td></td><td>Rood</td><td>Groen</td><td>Blauw</td><td>[kleur]</td></tr>
	  				<tr><td>Naam</td><td><input type="text" SIZE="2" value="<?= $cfg['cirkel']['standaard']['font']['kleur']['R']; ?>"/></td><td><input type="text" SIZE="2" value="<?= $cfg['cirkel']['standaard']['font']['kleur']['G']; ?>"/></td><td><input type="text" SIZE="2" value="<?= $cfg['cirkel']['standaard']['font']['kleur']['B']; ?>"/></td><td id="color_naam"></td></tr>
	  				
	  				</table>
	  				
	  			</div>
	  			<div class="column-right">
	  				<div id="Circel_Example"><img src="../paginas/gedragscirkel.png.php?admin_example"></div>
	  			</div>
	  			<div class="clear"></div>
	  			<div class="action_bar">
	  				<input type="submit" class="button blue" value="Opslaan" onclick=""/>
	  			    <a href="#modal" class="modal button">Annuleren</a>
	  			</div>
	  			
	  		</form>
	  	</div>
	</div>
	<div class="box">
		<div class="box-header">
			<h1>Gedragcirkel tekst posities</h1>
		</div>
		<div class="box-content">
	  		<form action="javascript:;" method="post" id="general" >
	  			<div class="column">
	  				<p>Hieronder staan de coördinaten van de eigenschappen die in de cirkel geplaatst worden</p>
	  				<table>
	  				<tr><td>Positie</td><td colspan="2">Werk</td><td colspan="2">Kinderen</td><td colspan="2">Volwassenen</td><td colspan="2">Ik</td></tr>
	  				<tr><td></td><td>x</td><td>y</td><td>x</td><td>y</td><td>x</td><td>y</td><td>x</td><td>y</td></tr>
	  				<?
	  				for ($i = 0; $i < 10; $i++) {
	  					echo "<tr><td>".($i+1)."</td>";
	  					echo "<td><input type=\"text\" id=\"title\" name=\"title\" SIZE=\"2\" value=\"".$cfg['cirkel']['eigenschapen']['positie']['werk']['links'][$i]."\"/></td>";
	  					echo "<td><input type=\"text\" id=\"title\" name=\"title\" SIZE=\"2\" value=\"".$cfg['cirkel']['eigenschapen']['positie']['werk']['top'][$i]."\"/></td>";
	  					
	  					echo "<td><input type=\"text\" id=\"title\" name=\"title\" SIZE=\"2\" value=\"".$cfg['cirkel']['eigenschapen']['positie']['kinderen']['links'][$i]."\"/></td>";
	  					echo "<td><input type=\"text\" id=\"title\" name=\"title\" SIZE=\"2\" value=\"".$cfg['cirkel']['eigenschapen']['positie']['kinderen']['top'][$i]."\"/></td>";
	  					
	  					echo "<td><input type=\"text\" id=\"title\" name=\"title\" SIZE=\"2\" value=\"".$cfg['cirkel']['eigenschapen']['positie']['volwassenen']['links'][$i]."\"/></td>";
	  					echo "<td><input type=\"text\" id=\"title\" name=\"title\" SIZE=\"2\" value=\"".$cfg['cirkel']['eigenschapen']['positie']['volwassenen']['top'][$i]."\"/></td>";
	  					
	  					echo "<td><input type=\"text\" id=\"title\" name=\"title\" SIZE=\"2\" value=\"".$cfg['cirkel']['eigenschapen']['positie']['ik']['links'][$i]."\"/></td>";
	  					echo "<td><input type=\"text\" id=\"title\" name=\"title\" SIZE=\"2\" value=\"".$cfg['cirkel']['eigenschapen']['positie']['ik']['top'][$i]."\"/></td>";
	  			
	  					echo "</tr>";
	  					
	  				}
	  				?>
	  				</table>
	  				
	  			</div>
	  			<div class="clear"></div>
	  			<div class="action_bar">
	  				<input type="submit" class="button blue" value="Opslaan" onclick=""/>
	  			    <a href="#modal" class="modal button">Annuleren</a>
	  			</div>
	  			
	  		</form>
	  	</div>
	</div>
	
	  <div class="box-content">
	<div class="box">
	  <div class="box-header">
	    <h1>Gedragcirkel eigenschappen</h1>
	  </div>
	
	  <div class="box-content">
	      <form action="/" method="post">
	        <div class="column">
	          <p>
	          	hier geeft u aan uit welke eigenschappen er gekozen kan worden bij de gedragcirkel. u kunt dit per onderdeel aangeven
	          </p>
	          <h2>Ik ben:</h2>
	          <p>
	            <textarea id="cfg_general_eigenschappen_ik" name="cfg['general']['eigenschappen']['ik']" class="taginput" placeholder="Eigenschap.."><?=$eigenschappen['ik'];?></textarea>
	          </p>
	        <h2>Ik ben tegenover Werk:</h2>
	          <p>
	            <textarea id="cfg_general_eigenschappen_werk" name="cfg['general']['eigenschappen']['werk']" class="taginput" placeholder="Eigenschap.."><?=$eigenschappen['werk'];?></textarea>
	          </p>
	        <h2>Ik ben tegenover volwassenen:</h2>
	          <p>
	            <textarea id="cfg_general_eigenschappen_volwassenen" name="cfg['general']['eigenschappen']['volwassenen']" class="taginput" placeholder="Eigenschap.."><?=$eigenschappen['volwassenen'];?></textarea>
	          </p>
	         <h2>Ik ben tegenover kinderen:</h2>
	           <p>
	             <textarea id="cfg_general_eigenschappen_kinderen" name="cfg['general']['eigenschappen']['kinderen']" class="taginput" placeholder="Eigenschap.."><?=$eigenschappen['kinderen'];?></textarea>
	           </p>
	        </div>
	        <div class="clear"></div>
	
	        <div class="action_bar">
	          <input type="submit" class="button blue" value="Submit Post" onclick="alert($('#cfg_general_eigenschappen_ik').val())"/>
	          <a href="#modal" class="modal button">Cancel</a>
	        </div>
	
	      </form>
	   </div>
	</div>
	
	<script type="text/javascript">
		$(document).ready(function() {
			$('#color_naam').css('background-color', 'rgb(<?= $cfg['cirkel']['standaard']['font']['kleur']['R']; ?>,<?= $cfg['cirkel']['standaard']['font']['kleur']['G']; ?>,<?= $cfg['cirkel']['standaard']['font']['kleur']['B']; ?>)');
		});
	</script>
	<?


}else{
?>
<script>
var html ='<ul>';
html +='  <li class="active"><a href="./pages/settings.php?general">Algemeen</a></li>';
html +='  <li><a href="./pages/settings.php?Gedragcirkel">Gedragcirkel</a></li>';
html +='  <li><a href="./pages/settings.php?database">Database</a></li>';
html +='  <li><a href="./pages/settings.php?mail">Mail</a></li>';
html +='</ul>';
$('#secondary').html(html);
$('#secondary').fadeIn('fast');

$(document).ready(function() {
	$('#main').fadeOut('fast', function() {
		$('#main').load('./pages/settings.php?general', function() {
			$('#main').fadeIn('fast');
		});
	});

	
    $('#secondary ul li a').click(function(e) {
  		// voorkom dat de link gevolgd wordt
    	e.preventDefault(); 
    	var link =$(this).attr("href");
    	if(link != "#"){
        	//laad de pagina in  #Main container
        	$('#main').fadeOut('fast', function() {
        		$('#main').load(link, function() {
        			$('#main').fadeIn('fast');
        		});
        	});
        	$("#secondary ul li").removeClass("active");
        	$(this).parent().addClass("active");	
        }else{
        	alert('Sorry maar deze pagina bestaat nog niet');
        }
    });
});
</script> 
<?}?>